package file.day9_19.day04;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemoFlush {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos = new FileOutputStream("dos.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);//如果boolean为true，
        // 每当我们调用它的println方法写出一行字符串后就会自动flush()一次。

        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("请输入内容：");
            String data = scanner.nextLine();
            if(data.equals("exit")){
                pw.close();
                System.out.println("写出结束");
                break;
            }
            pw.println(data);
        }
    }
}
